The scoop on 's marks

Usually, for documents of class book and report, you may want to use chapter and section information in the headings (chapter only for one-sided printing), and for documents of class article, section and subsection information (section only for one-sided printing). uses a marker mechanism to remember the chapter and section (section and subsection) information for a page; this is discussed in detail in the Companion, Section 4.3.1.

There are two ways you can use and change the higher- and lower-level sectioning information available to you. The macros: \leftmark (higher-level) and \rightmark (lower-level) contain the information processed by , and you can use them directly as shown in Section [*].

The \leftmark contains the left argument of the last \markboth on the page, the \rightmark contains the right argument of the first \markboth or the only argument of the first \markright on the page. If no marks are present on a page they are ``inherited'' from the previous page.

You can influence how chapter, section, and subsection information (only two of them!) is displayed by redefining the \chaptermark, \sectionmark, and \subsectionmark commands2. You must put the redefinition after the first call of \pagestyle{fancy} as this sets up the defaults.

Let us illustrate this with chapter info. It is made up of three parts:

Figure [*] shows some variants for ``Chapter 2. Do it now'' (the last example is appropriate in some non-English languages).

Figure: Marker variants
\begin{figure}\index{chaptermark@\texttt{\symbol{'134}chaptermark}}
\index{upper...
...\\
\mbox{}\\
2.\ Chapter.\ Do it now\\
\mbox{}\\
\end{multicols}\end{figure}

For the lower-level sectioning information, do the same with \markright.

So if ``Section 2.2. First steps'' is the current section, then

\renewcommand{\sectionmark}[1]{
   \markright{\thesection.\ #1}}
will give ``2.2. First steps''

Redefining the \chaptermark and \sectionmark commands may not eliminate all uppercaseness. E.g. the bibliography will have a title of BIBLIOGRAPHY in the header, as the \uppercase is explicitly given in the definition of \thebibliography. Similar for INDEX etc. If you don't want to redefine these commands, you can use an ugly hack like the following:

\lhead{\let\uppercase\relax\rightmark}
\rhead{\let\uppercase\relax\leftmark}

It should be noted that the marking mechanism works fine with chapters (which always start on a new page) and sections (which are reasonably long). It does not work quite as well with short sections and subsections. This is a problem with , not with fancyheadings.

As an example let's take a page layout where the leftmarks are generated by the sections and the rightmarks by the subsections (as is default in the article class). Take a page with some short sections, e.g.

Section 1.
subsection 1.1
subsection 1.2
Section 2.

As the leftmark contains the last mark of the page it will be ``Section 2.'', and the rightmark will be ``subsection 1.1'' as it will be the first mark of the page. So the page header info will combine section 2 with subsection 1.1 which isn't very nice. The best you can do in these cases is use only the \rightmarks and redefine \sectionmark accordingly. A command \firstleftmark would also be a nice addition (see the extramarks package in section [*]).

Another problem with the marks in the standard classes is that the higher level sectioning commands (e.g. \chapter) call \markboth with an empty right argument. This means that on the first page of a chapter (or a section in article style) the \rightmark will be empty. If this is a problem you must manually insert extra \markright commands or redefine the \chaptermark (\sectionmark) commands to issue a \markboth command with two decent parameters.

As a final remark you should also note that the * forms of the \chapter etc. commands do not call the mark commands. So if you want your preface to set the header info but not be numbered nor be put in the table of contents, you must issue the \markboth command yourself, e.g.

\chapter*{Preface\markboth{Preface}{}}

Entering the \markboth command inside the \chapter* insures that the mark will not be separated from the title by a page break. Of course with \chapter this wouldn't be a problem if you put the mark command after the chapter title, as the \chapter command starts at a new page. However with a \section* it could be dangerous to say:

\section*{Preface}
\markboth{Preface}{}
as a page break may occur between the two commands.